import { reactive, onMounted } from 'vue';
import axios from 'axios';

export default function () {
    let dogList = reactive([
        'https://images.dog.ceo/breeds/pembroke/n02113023_3945.jpg',
    ]);
    async function getDog() {
        try {
            let result = await axios.get(
                'https://dog.ceo/api/breed/pembroke/images/random',
            );
            dogList.push(result.data.message);
        } catch (error) {
            alert(error);
        }
    }

    // 挂载完毕钩子
    onMounted(() => {
        console.log('dog--挂载完毕');
        getDog();
    });
    //向外部提供东西
    return { dogList, getDog };
}
